package demo13.Practice01;

public class DFlockSimulator {
	public static void main(String[] args) {
		DFlockSimulator dfs = new DFlockSimulator();
		AbstractDuckFactory duckFactory = new CountingDuckFactory();
		dfs.simulate(duckFactory);
		
	/*	鸭子组合开始统计鸭子叫
		绿头鸭子叫
		绿头鸭呱呱叫
		绿头鸭呱呱叫
		绿头鸭呱呱叫
		绿头鸭呱呱叫
		鸭子叫了4次
		鸭子群叫
		橡皮鸭子吱吱叫
		绿头鸭呱呱叫
		红头鸭子呱呱叫
		大鹅叫          //
		绿头鸭呱呱叫
		绿头鸭呱呱叫
		绿头鸭呱呱叫
		绿头鸭呱呱叫
		鸭子叫了11次*/
		//4 +7
		
	}

	
	//
	public void simulate(AbstractDuckFactory duckFactory){
		 Quackable mallarDuck = duckFactory.createMallardDuck();
		 Quackable redhradDuck = duckFactory.createRedheadDuck();
		 Quackable rubberDuck = duckFactory.createRubberDuck();
		 Quackable gooseDuck = new GooseAdapter(new Goose());//大鹅不去装饰
		 System.out.println("鸭子组合开始统计鸭子叫");
		
		 //创建鸭子组合群 、总群
		 Flock flockOfDucks = new Flock();
		flockOfDucks.add(rubberDuck);
		flockOfDucks.add(mallarDuck);
		flockOfDucks.add(redhradDuck);
		flockOfDucks.add(gooseDuck);
		//创建绿头鸭子组合群
		Flock  flockOfMallards = new Flock();
		Quackable mallardOne = duckFactory.createMallardDuck();
		Quackable mallardTwo = duckFactory.createMallardDuck();
		Quackable mallardThree = duckFactory.createMallardDuck();
		Quackable mallardFour = duckFactory.createMallardDuck();
		flockOfMallards.add(mallardOne);
		flockOfMallards.add(mallardTwo);
		flockOfMallards.add(mallardThree);
		flockOfMallards.add(mallardFour);
		//将路绿头鸭子装入鸭子总群
		flockOfDucks.add(flockOfMallards);
		System.out.println("绿头鸭子叫");
		simulate(flockOfMallards);//
		 System.out.println("鸭子叫了"+QuackCounter.getQuacks()+"次");
		 
		System.out.println("鸭子群叫");
		simulate(flockOfDucks);
		 System.out.println("鸭子叫了"+QuackCounter.getQuacks()+"次");
	}
	
	 public void simulate(Quackable duck){//多态
		 duck.query();
		 	 
	 }
}
